#include "as_session_mgr.h"


namespace as
{
namespace inet
{

void AsSessionMgr::bind(int sid, std::shared_ptr<as::inet::AsSession> &session)
{
    m_lock.LockWrite();
    m_sessionMap.insert({sid, session});
    m_lock.ReleaseWrite();
}

void AsSessionMgr::unbind(int sid)
{
    m_lock.LockWrite();
    m_sessionMap.erase(sid);
    m_lock.ReleaseWrite();
}

std::shared_ptr<as::inet::AsSession> AsSessionMgr::find(int sid)
{
    m_lock.LockRead();
    std::shared_ptr<as::inet::AsSession> s;
    auto sessionIt = m_sessionMap.find(sid);
    if(sessionIt != m_sessionMap.end())
    {
        s = sessionIt->second;
    }

    m_lock.ReleaseRead();
    return s;
}



}
}